package com.wx.mall.operate.controller;

import com.wx.mall.common.api.CommonPage;
import com.wx.mall.common.api.CommonResult;
import com.wx.mall.common.api.ResultCode;
import com.wx.mall.common.exceptions.ApiAssert;
import com.wx.mall.operate.dto.RebGoodsDto;
import com.wx.mall.operate.dto.RebGoodsTwoDto;
import com.wx.mall.operate.entity.RebGoods;
import com.wx.mall.operate.service.impl.RebGoodsServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author z
 * @since 2020-6-4
 */
@RestController
@RequestMapping("/reb/goods")
public class RebGoodsController {

    @Autowired
    RebGoodsServiceImpl rebGoodsService;

    @ApiOperation(value = "分页查询")
    @GetMapping("/getFindAllGoods")
    public CommonResult<CommonPage<RebGoods>> getFindAllList(RebGoodsDto dto){
        if (dto.getPageNum() == null || dto.getPageSize() == null){
            ApiAssert.fail(ResultCode.VALIDATE_FAILED);
        }
        if (dto.getPageNum() == 0){
            ApiAssert.fail("无效页码");
        }
        List<RebGoods> allGoods = rebGoodsService.findAllGoods(dto);
        return CommonResult.success(CommonPage.restPage(allGoods));
    }

    @ApiOperation(value = "筛选查询")
    @GetMapping("/getPageScreenGoods")
    public CommonResult<CommonPage<RebGoods>> getScreenGoods(RebGoodsTwoDto dto){
        if (dto.getPageNum() == null || dto.getPageSize() == null){
            ApiAssert.fail(ResultCode.VALIDATE_FAILED);
        }
        if (dto.getPageNum() == 0){
            ApiAssert.fail("无效页码");
        }
        List<RebGoods> screenGoods = rebGoodsService.findScreenGoods(dto);
        return CommonResult.success(CommonPage.restPage(screenGoods));
    }
}
